/**
 * Created by leon on 2017/5/8.
 */
(function () {
    'use strict';
    angular.module('App.pages.member')
        .controller('ChangeRalCtrl',ChangeRalCtrl);
    function ChangeRalCtrl(studentId,$scope,MemberModel,AppUtils,$window,LoginAccountAuth) {
        $scope.$on('$ionicView.beforeEnter', function (event, viewData) {
            viewData.enableBack = true;
        });
        var vm = this;
        vm.name = "";

        vm.test = function (obj) {
            vm.name = obj;
        }
        var objParams = {};
        objParams.relmemberId = studentId;

        LoginAccountAuth.getAccount().then(function(data){
            vm.loginAccount = data;
            $scope.save = function () {
                objParams.relType = vm.name;
                objParams.memberId = data.memberId;
                if (AppUtils.isUndefinedOrNull(vm.name)){
                    AppUtils.showTipsTop("请选择输入亲属关系！");
                    return false;
                }
                MemberModel.changeRel(objParams).$promise.then(function (response) {
                    var result = response.result;
                    if (!AppUtils.isUndefinedOrNull(result) && result == 'success') {
                        AppUtils.showTipsTop("更改成功！");
                        $window.location.reload();
                    }
                })
            }

            MemberModel.getfamilyInfo({"rememberId":objParams.relmemberId}).$promise.then(function (response) {
                if (!AppUtils.isUndefinedOrNull(response.familyInfo)) {
                    vm.familyInfo = response.familyInfo;
                } else {
                    AppUtils.showTipsTop("未查询到您亲友的信息！");
                }
            })

        })
    }
})();